/**
 * 
 */
package com.sugou.web.ctrl;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.servlet.http.HttpServletRequest;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * 脚本 css js装载页面
 * @version 1.0 
 * @author Hunk.Tong &copy; Ustudy 游学网络
 * <b>Create Time:</b>2013-2-7 下午2:49:51
 */
@Controller
@RequestMapping(value="/script")
@Scope("prototype")
public class ScriptCtrl extends WebControllerSupport {
	private static final long serialVersionUID = 8415471270992637004L;
	
	public static final Pattern jsPtn=Pattern.compile("^/script/js/(.*\\.jsx)$");
	
	@RequestMapping(value="/js/**/*.jsx",method={RequestMethod.GET})
	public String loadJS(){
		try{
		HttpServletRequest request=this.request;
		String requestPath=request.getServletPath();
		this.response.setContentType("application/x-javascript");
		Matcher m=jsPtn.matcher(requestPath);
		if(m.matches()){
			StringBuilder path=new StringBuilder("/js/").append(m.group(1));
			return path.toString();
		}else{
			return "";
		}
		}catch(Exception e){
			e.printStackTrace();
			return "";
		}
	}
}
